#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e5 + 5;

set<int> s;
int n, x, a[N];

int main() {
    cin >> n >> x ;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    int cur = x;
    while(s.find(cur) == s.end()) {
        s.insert(cur);
        cur = a[cur];
    }
    cout << s.size() << endl;
    return 0;
}